package com.example.apple_starter.config;

import com.example.apple_starter.properties.AppleServiceProperties;
import com.example.apple_starter.service.AppleBuilder;
import com.example.apple_starter.service.AppleService;
import com.example.apple_starter.service.Builder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration

/**
 * 引入ApplceService
 */
@ConditionalOnClass({AppleService.class, Builder.class, AppleBuilder.class})
// 将 ApplceServiceAutoConfigation.properties 的相关的属性字段与该类一一对应，并生成 Bean
@EnableConfigurationProperties(AppleServiceProperties.class)
public class ApplceServiceAutoConfigation {
    @Autowired
    AppleServiceProperties appleServiceProperties;
    @Bean
    @ConditionalOnMissingBean(AppleService.class)
    public AppleService appleService() {
        AppleBuilder builder = new AppleBuilder();
        builder.BuilderRedAppleA(appleServiceProperties.getName(), appleServiceProperties.getRangeForBig(), appleServiceProperties.getRangeForPrice(), appleServiceProperties.getColor());
        return new AppleService().AppleServiceBuilder(builder);
    }
}
